package com.example.iotmanagerment26.controller;

import com.example.iotmanagerment26.domain.Device;
import com.example.iotmanagerment26.domain.JsonData;
import com.example.iotmanagerment26.service.CatService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 作者：太难猫
 * 创建时间： 2025/6/17 10:37
 */

@CrossOrigin
@RestController
@RequestMapping("/v1/car")
@Tag(name="停车场管理",description = "停车场管理的接口")
public class CarController {

    @Autowired
    CatService catService;

    @PostMapping("/carJoin")
    @Operation(summary = "车辆入库")
    public JsonData carJoin() {
        int result = catService.join();
        if (result>=1) {
            return new JsonData(1,result,"入库成功");
        }else {
            return new JsonData(0,result,"入库失败");
        }
    }

    @PostMapping("/carQuit")
    @Operation(summary = "车辆出库")
    public JsonData carQuit() {
        int result = catService.quit();
        if (result>=1) {
            return new JsonData(1,result,"出库成功");
        }else {
            return new JsonData(0,result,"出库失败");
        }
    }

    @PostMapping("/carSet")
    @Operation(summary = "停车场车辆设置")
    public JsonData carSet(int num) {
        int result = catService.set(num);
        if (result>=1) {
            return new JsonData(1,result,"设置成功");
        }else {
            return new JsonData(0,result,"设置失败");
        }
    }

    @GetMapping("/carGet")
    @Operation(summary = "获取停车场车辆数量")
    public JsonData carGet() {
        Map<String,Object> result = catService.get();
        if (result!=null) {
            return new JsonData(1,result,"获取成功");
        }else {
            return new JsonData(0,result,"获取失败");
        }
    }
}
